define(["jquery", "easy-admin", "echarts", "echarts-theme", "miniAdmin", "miniTab","okLayer"], function ($, ea, echarts, undefined, miniAdmin, miniTab,okLayer) {
    var Controller = {
        index: function () {
            var options = {
                iniUrl: ea.url('ajax/initAdmin'),    // 初始化接口
                clearUrl: ea.url("ajax/clearCache"), // 缓存清理接口
                urlHashLocation: true,      // 是否打开hash定位
                bgColorDefault: false,      // 主题默认配置
                multiModule: true,          // 是否开启多模块
                menuChildOpen: false,       // 是否默认展开菜单
                loadingTime: 0,             // 初始化加载时间
                pageAnim: true,             // iframe窗口动画
                maxTabNum: 20,              // 最大的tab打开数量
            };
            miniAdmin.render(options);

            $('.login-out').on("click", function () {
                ea.request.get({
                    url: 'login/out',
                    prefix: true,
                }, function (res) {
                    ea.msg.success(res.msg, function () {
                        window.location = ea.url('login/index');
                    })
                });
            });
        },
        welcome: function () {

            miniTab.listen();

            /**
             * 查看公告信息
             **/
            $('body').on('click', '.layuimini-notice', function () {
                var title = $(this).children('.layuimini-notice-title').text(),
                    noticeTime = $(this).children('.layuimini-notice-extra').text(),
                    content = $(this).children('.layuimini-notice-content').html();
                var html = '<div style="padding:15px 20px; text-align:justify; line-height: 22px;border-bottom:1px solid #e2e2e2;background-color: #2f4056;color: #ffffff">\n' +
                    '<div style="text-align: center;margin-bottom: 20px;font-weight: bold;border-bottom:1px solid #718fb5;padding-bottom: 5px"><h4 class="text-danger">' + title + '</h4></div>\n' +
                    '<div style="font-size: 12px">' + content + '</div>\n' +
                    '</div>\n';
                layer.open({
                    type: 1,
                    title: '系统公告' + '<span style="float: right;right: 1px;font-size: 12px;color: #b1b3b9;margin-top: 1px">' + noticeTime + '</span>',
                    id: 'layuimini-notice',
                    content: html,
                });
            });

          
            $.ajax({
                url:ea.url('index/getDataAnalysis'),
                dataType: 'json',
                // data : JSON.stringify(params),
                contentType: "application/json",  
                type: 'post',
                success: function (data) {
                        
                     /**
                     * 报表功能
                     */
                    var echartsRecords = echarts.init(document.getElementById('echarts-records'));
                    var optionRecords = {
                        title: {
                            text: '售票统计'
                        },
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                              type: 'cross',
                              crossStyle: {
                                color: '#999'
                              }
                            }
                        },
                        legend: {
                            data: data.data.names
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                         toolbox: {
                            feature: {
                              dataView: { show: true, readOnly: false },
                              magicType: { show: true, type: ['line', 'bar'] },
                              restore: { show: true },
                              saveAsImage: { show: true }
                            }
                          },
                         xAxis: [
                            {
                              type: 'category',
                              data: data.data.month,
                              axisPointer: {
                                type: 'shadow'
                              }
                            }
                          ],
                          yAxis: [
                            {
                              type: 'value',
                              name: '总金额',
                            
                              axisLabel: {
                                formatter: '{value} 元'
                              }
                            },  {
                              type: 'value',
                              name: '票数',
                             
                              axisLabel: {
                                formatter: '{value} 张'
                              }
                            }
                          ],
                        series:data.data.lists
                    };
                    echartsRecords.setOption(optionRecords);
                    window.addEventListener("resize", function () {
                        echartsRecords.resize();
                    });
                }
            });
             $.ajax({
                url:ea.url('index/getDataAnalysisLease'),
                dataType: 'json',
                // data : JSON.stringify(params),
                contentType: "application/json",  
                type: 'post',
                success: function (data) {
                        
                     /**
                     * 报表功能
                     */
                    var echartsRecords = echarts.init(document.getElementById('echarts-lease'));
                    var optionRecords = {
                        title: {
                            text: '租赁统计'
                        },
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                              type: 'cross',
                              crossStyle: {
                                color: '#999'
                              }
                            }
                        },
                        legend: {
                            data: data.data.names
                        },
                        grid: {
                            left: '3%',
                            right: '4%',
                            bottom: '3%',
                            containLabel: true
                        },
                         toolbox: {
                            feature: {
                              dataView: { show: true, readOnly: false },
                              magicType: { show: true, type: ['line', 'bar'] },
                              restore: { show: true },
                              saveAsImage: { show: true }
                            }
                          },
                         xAxis: [
                            {
                              type: 'category',
                              data: data.data.month,
                              axisPointer: {
                                type: 'shadow'
                              }
                            }
                          ],
                          yAxis: [
                            {
                              type: 'value',
                              name: '总金额',
                            
                              axisLabel: {
                                formatter: '{value} 元'
                              }
                            },  {
                              type: 'value',
                              name: '次数',
                             
                              axisLabel: {
                                formatter: '{value} 人次'
                              }
                            }
                          ],
                        series:data.data.lists
                    };
                    echartsRecords.setOption(optionRecords);
                    window.addEventListener("resize", function () {
                        echartsRecords.resize();
                    });
                }
            });
            
        },
        editAdmin: function () {
            ea.listen();
        },
        editPassword: function () {
            ea.listen();
        }
    };
    return Controller;
});
